<template>
  <div class="ma-content-block">
    <sa-table ref="crudRef" :options="options" :columns="columns" :searchForm="searchForm">
      <!-- 搜索区 tableSearch -->
      <template #tableSearch>
		  <a-col :span="8">
		    <a-form-item label="政策名称" field="policy_title">
		      <a-input v-model="searchForm.policy_title" placeholder="请输入政策名称" />
		    </a-form-item>
		  </a-col>
        <a-col :span="8">
          <a-form-item label="公司名称" field="company_name">
            <a-input v-model="searchForm.company_name" placeholder="请输入公司名称" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="姓名" field="name">
            <a-input v-model="searchForm.name" placeholder="请输入姓名" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="电话" field="phone">
            <a-input v-model="searchForm.phone" placeholder="请输入电话" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="职位" field="position">
            <a-input v-model="searchForm.position" placeholder="请输入职位" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="申报时间" field="create_time">
            <a-range-picker v-model="searchForm.create_time" :show-time="true" mode="date" />
          </a-form-item>
        </a-col>
      </template>

      <!-- Table 自定义渲染 -->
    </sa-table>

    <!-- 编辑表单 -->
    <edit-form ref="editRef" @success="refresh" />
  </div>
</template>

<script setup>
import { onMounted, ref, reactive } from 'vue'
import { Message } from '@arco-design/web-vue'
import EditForm from './edit.vue'
import api from '../api/application'

// 引用定义
const crudRef = ref()
const editRef = ref()

// 搜索表单
const searchForm = ref({
	policy_title:'',
  company_name: '',
  name: '',
  phone: '',
  position: '',
  create_time: [],
})


// SaTable 基础配置
const options = reactive({
  api: api.getPageList,
  // recycleApi: api.getRecyclePageList,
  rowSelection: { showCheckedAll: true },
   operationColumn:false,
  add: {
    show: false,
    auth: ['/EbPolicyApplication/EbPolicyApplication/save'],
    func: async () => {
      editRef.value?.open()
    },
  },
  edit: {
    show: false,
    auth: ['/EbPolicyApplication/EbPolicyApplication/update'],
    func: async (record) => {
      editRef.value?.open('edit')
      editRef.value?.setFormData(record)
    },
  },
  delete: {
    show: false,
    auth: ['/EbPolicyApplication/EbPolicyApplication/destroy'],
    func: async (params) => {
      const resp = await api.delete(params)
      if (resp.code === 200) {
        Message.success(`删除成功！`)
        crudRef.value?.refresh()
      }
    },
    realAuth: ['/EbPolicyApplication/EbPolicyApplication/realDestroy'],
    realFunc: async (params) => {
      const resp = await api.realDestroy(params)
      if (resp.code === 200) {
        Message.success(`销毁成功！`)
        crudRef.value?.refresh()
      }
    },
  },
  recovery: {
    show: false,
    auth: ['/EbPolicyApplication/EbPolicyApplication/recovery'],
    func: async (params) => {
      const resp = await api.recovery(params)
      if (resp.code === 200) {
        Message.success(`恢复成功！`)
        crudRef.value?.refresh()
      }
    },
  },
  export: { show: true, url: '/EbPolicyApplication/EbPolicyApplication/export', auth: ['/EbPolicyApplication/EbPolicyApplication/export'] },
})

// SaTable 列配置
const columns = reactive([
  { title: '申报政策名称', dataIndex: 'PolicyMatching.policy_title', width: 180 },
  { title: '申报公司名称', dataIndex: 'company_name', width: 180 },
  { title: '统一社会信用代码', dataIndex: 'credit_code', width: 180 },
  { title: '申报人姓名', dataIndex: 'name', width: 180 },
  { title: '手机号码', dataIndex: 'phone', width: 180 },
  { title: '公司职务', dataIndex: 'position', width: 180 },
  
  { title: '申报时间', dataIndex: 'create_time', width: 180 },
])

// 页面数据初始化
const initPage = async () => {}

// SaTable 数据请求
const refresh = async () => {
  crudRef.value?.refresh()
}

// 页面加载完成执行
onMounted(async () => {
  initPage()
  refresh()
})
</script>
